﻿using PDFDesign.Model;

namespace PDFDesign.ViewModel
{
    public class CellViewModel : BaseViewModel
    {
        public CellViewModel(Cell cell)
        {
            Cell = cell;
            name = cell.Name;
            origin = cell.Origin;
            value = cell.Value;
            columnSpan = cell.ColumnSpan;
            merger = cell.Merger;
            groupName = cell.GroupName;
            dataField = cell.DataField;
            textstyle = new TextStyleViewModel(cell.TextStyle);
        }

        public Cell Cell { get; set; }

        public void Save()
        {
            Cell.Name = name;
            Cell.Origin = origin;
            Cell.Value = value;
            Cell.ColumnSpan = columnSpan;
            Cell.Merger = merger;
            Cell.GroupName = groupName;
            Cell.DataField = dataField;
            textstyle.Save();
            Cell.TextStyle = textstyle.Textstyle;
        }

        private string name;
        public string Name
        {
            get => name;
            set
            {
                name = value;
                OnPropertyChanged("Name");
            }
        }

        private DataOrigin origin = DataOrigin.value;
        public DataOrigin Origin
        {
            get => origin;
            set
            {
                origin = value;
                OnPropertyChanged("Origin");
            }
        }

        private string value;
        public string Value
        {
            get => value;
            set
            {
                this.value = value;
                OnPropertyChanged("Value");
            }
        }

        private int columnSpan;
        public int ColumnSpan
        {
            get => columnSpan;
            set
            {
                columnSpan = value;
                OnPropertyChanged("ColumnSpan");
            }
        }

        private bool merger;
        public bool Merger
        {
            get => merger;
            set
            {
                merger = value;
                OnPropertyChanged("Merger");
            }
        }

        private string groupName;
        public string GroupName
        {
            get => groupName;
            set
            {
                groupName = value;
                OnPropertyChanged("GroupName");
            }
        }

        private string dataField;
        public string DataField
        {
            get => dataField;
            set
            {
                dataField = value;
                OnPropertyChanged("DataField");
            }
        }

        private TextStyleViewModel textstyle;
        public TextStyleViewModel Textstyle
        {
            get => textstyle;
            set
            {
                textstyle = value;
                OnPropertyChanged("Textstyle");
            }
        }
    }
}
